home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C20 / WordList2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  1.0 KB  |  40 lines

  1. //: C20:WordList2.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Eliminating strtok() from Wordlist.cpp
  7. #include "../require.h"
  8. #include <string>
  9. #include <cstring>
  10. #include <set>
  11. #include <iostream>
  12. #include <fstream>
  13. #include <iterator>
  14. using namespace std;
  15.  
  16. int main(int argc, char* argv[]) {
  17.   using namespace std;
  18.   requireArgs(argc, 1);
  19.   ifstream in(argv[1]);
  20.   assure(in, argv[1]);
  21.   istreambuf_iterator<char> p(in), end;
  22.   set<string> wordlist;
  23.   while (p != end) {
  24.     string word;
  25.     insert_iterator<string> 
  26.       ii(word, word.begin());
  27.     // Find the first alpha character:
  28.     while(!isalpha(*p) && p != end)
  29.       p++;
  30.     // Copy until the first non-alpha character:
  31.     while (isalpha(*p) && p != end)
  32.       *ii++ = *p++;
  33.     if (word.size() != 0)
  34.       wordlist.insert(word);
  35.   } 
  36.   // Output results:
  37.   copy(wordlist.begin(), wordlist.end(),
  38.     ostream_iterator<string>(cout, "\n"));
  39. } ///:~
  40.